package com.woniuxy.controller;
import com.woniuxy.entity.User;
import com.woniuxy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/user")
public class UserControlloer {
    @Autowired(required = false)
     UserService userService;
    @GetMapping("/user")
    public String login(){
        return "sss";
    }
    @PostMapping("/login")
    public String login(String account, String password){
        User user= userService.login(account);
        if(user!=null){
            if(user.getPassword().equals(password)){
                return "/index.jsp";
            }else {
                return "/login.jsp";
            }

        }else{
            return "/login.jsp";
        }
    }
    @PostMapping("/inster")
    public String inster(User user){
        boolean b = userService.addUser(user);
        if(b){
            return "/login.jsp";
        }
        return "/adduser.jsp";
    }
}
